﻿using Decision.BusinessLayer;
using Decision.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            InitPage();
        }
    }

    private void InitPage()
    {
        BindData();
    }

    private void BindData()
    {
        BindData(null);
    }

    private void BindData(int? p)
    {
        List<QueryMasTerData> listMaster = DCSFactory.CreateQueryMasTerDataFactory().SelectByBusinessObject(new QueryMasTerDataCriteria
        {
            PageNum = GridResult.CurrentPageIndex + 1,
            PageSize = p != null ? p : GridResult.PageSize,
            START_SIGN_DATE = DateTime.Now,
            END_SIGN_DATE = DateTime.Now.AddDays(30),
            SortName = "RESULT_DATE",
            SortDirection = "DESC"
        });


        if (listMaster == null || listMaster.Count == 0) 
        {
            GridResult.DataSource = null;
            GridResult.VirtualItemCount = 0;
            GridResult.DataBind();
            return;
        }

        GridResult.DataSource = listMaster;
        GridResult.VirtualItemCount = (int)listMaster[0].RowAll;
        GridResult.DataBind();
    }
    protected void GridUserADmin_PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
    {
        GridResult.CurrentPageIndex = e.NewPageIndex;
        this.BindData(null);
    }
    protected void GridUserADmin_PageSizeChanged(object sender, Telerik.Web.UI.GridPageSizeChangedEventArgs e)
    {
        GridResult.CurrentPageIndex = 0;
        this.BindData(e.NewPageSize);
    }
    protected void GoTo_Click(object sender, EventArgs e)
    {
        string masterID = ((RadButton)sender).CommandArgument;
        Util.jsRedirect(Page, "register.aspx?masterID=" + (masterID));
    }
}